package com.itheima.edu.javagaoji.thread2;

public class Ticket implements Runnable {

    private int ticket = 100;
    Object q = new Object();

    @Override
    public void run() {



        synchronized (q){
            while (true){

                if (ticket == 0){
                    break;
                }else {


                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }



                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "在买票还剩下" + ticket +"张票"  );

                }


            }
        }





    }
}
